package lib.logging;

import org.fusesource.jansi.AnsiConsole;

/**
 * Provides logging functionality to console in different colors
 *
 * @implements {@link ILogger}
 * @author abhip
 *
 */
public class ANSIConsoleLogger implements ILogger {
    private static final String ANSI_RED = "\u001B[31m";
    private static final String ANSI_RESET = "\u001B[0m";
    private static final String ANSI_YELLOW = "\u001B[33m";

    public ANSIConsoleLogger() {
        AnsiConsole.systemInstall();
    }

    /**
     * Logs error message to console in red color
     *
     * @param errorFormatString
     * @param args
     */
    @Override
    public void LogError(String errorFormatString, Object... args) {
        AnsiConsole.err.print(ANSI_RED);
        AnsiConsole.err.format(errorFormatString, args);
        AnsiConsole.err.println();
        AnsiConsole.err.println(ANSI_RESET);
    }

    /**
     * Logs exception to console in red color
     *
     * @param e
     */
    @Override
    public void LogException(Exception e) {
        AnsiConsole.err.print(ANSI_RED);
        AnsiConsole.err.format(e.toString());
        AnsiConsole.err.println();
        AnsiConsole.err.println(ANSI_RESET);
    }

    /**
     * Logs info message to console in green color
     *
     * @param infoFormatString
     * @param args
     */
    @Override
    public void LogInfo(String infoFormatString, Object... args)
    {
        AnsiConsole.out.print(ANSI_YELLOW);
        AnsiConsole.out.format(infoFormatString, args);
        AnsiConsole.out.println();
        AnsiConsole.out.println(ANSI_RESET);
    }
}
